package com.hhcf.crotroller;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.jms.Destination;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hhcf.service.ProducerService;

/**
 * 
 * @ClassName: ConsumerCrotroller
 * @Description:
 * @author: zhaotf
 * @date: 2017年2月19日 下午2:34:30
 */
@Controller
@RequestMapping("/consumerCrotroller")
public class ConsumerCrotroller {

	@Autowired
	private ProducerService producerService;
	// 队列名gzframe.demo
	@Resource(name = "demoQueueDestination")
	private Destination demoQueueDestination;

	/**
	 * 通过kafka改善消息
	 * 
	 * @return Object
	 */
	@RequestMapping("/sndMesForTemplate")
	@ResponseBody
	public Object sndMesForTemplate() {
		// String topic = "ztfTopic";
		// Map<String, Object> data = new HashMap<String, Object>();
		// data.put("KEY1", 123);
		// data.put("KEY2", "test,kafka
		// 生产端测试，工工aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
		// data.put("KEY3", new Date());
		//
		// String ifPartition = "1";// 是否使用分区 0是\1不是
		// Integer partitionNum = 3;
		// String role = "test";// 用来生成key
		return producerService.sendMessage("test,activeMQ 生产端测试，工工aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
	}

	/**
	 * 模拟kafka官方示例：生产端
	 * 
	 * @return Object
	 */
	@RequestMapping("/sndMsg")
	@ResponseBody
	public Object sndMsg() {
		Map<String, Object> data = new HashMap<String, Object>();
		data.put("KEY1", 123);
		data.put("KEY2", "test,kafka 生产端测试,EDSJ");
		data.put("KEY3", new Date());
		producerService.sendMessage(demoQueueDestination, "keyztf");
		return "aaa";
	}

	// @RequestMapping(value = "/producer", method = RequestMethod.GET)
	// public ModelAndView producer() {
	// System.out.println("------------go producer");
	//
	// Date now = new Date();
	// SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd
	// HH:mm:ss");
	// String time = dateFormat.format(now);
	// System.out.println(time);
	//
	// ModelAndView mv = new ModelAndView();
	// mv.addObject("time", time);
	// mv.setViewName("jms_producer");
	// return mv;
	// }

	// @RequestMapping(value = "/onsend", method = RequestMethod.POST)
	// public ModelAndView producer(@RequestParam("message") String message) {
	// System.out.println("------------send to jms");
	// ModelAndView mv = new ModelAndView();
	// producerService.sendMessage(demoQueueDestination, message);
	// mv.setViewName("welcome");
	// return mv;
	// }

}
